package com.ruoyi.project.module.cloudAcc.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.constant.BusinessType;
import com.ruoyi.project.module.cloudAcc.domain.CloudAcc;
import com.ruoyi.project.module.cloudAcc.service.ICloudAccService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 云加速管理 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-07-19
 */
@Controller
@RequestMapping("/module/cloudAcc")
public class CloudAccController extends BaseController
{
    private String prefix = "module/cloudAcc";
	
	@Autowired
	private ICloudAccService cloudAccService;
	
	@RequiresPermissions("module:cloudAcc:view")
	@GetMapping()
	public String cloudAcc()
	{
	    return prefix + "/cloudAcc";
	}
	
	/**
	 * 查询云加速管理列表
	 */
	@RequiresPermissions("module:cloudAcc:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(CloudAcc cloudAcc)
	{
		startPage();
        List<CloudAcc> list = cloudAccService.selectCloudAccList(cloudAcc);
		return getDataTable(list);
	}
	
	/**
	 * 新增云加速管理
	 */
	@RequiresPermissions("module:cloudAcc:add")
	@Log(title = "云加速管理", action = BusinessType.INSERT)
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}

	/**
	 * 修改云加速管理
	 */
	@RequiresPermissions("module:cloudAcc:edit")
	@Log(title = "云加速管理", action = BusinessType.UPDATE)
	@GetMapping("/edit/{cloudId}")
	public String edit(@PathVariable("cloudId") Integer cloudId, Model model)
	{
		CloudAcc cloudAcc = cloudAccService.selectCloudAccById(cloudId);
		model.addAttribute("cloudAcc", cloudAcc);
	    return prefix + "/edit";
	}
	
	/**
	 * 保存云加速管理
	 */
	@RequiresPermissions("module:cloudAcc:save")
	@Log(title = "云加速管理", action = BusinessType.SAVE)
	@PostMapping("/save")
	@ResponseBody
	public AjaxResult save(CloudAcc cloudAcc)
	{
		if (cloudAccService.saveCloudAcc(cloudAcc) > 0)
		{
			return success();
		}
		return error();
	}
	
	/**
	 * 删除云加速管理
	 */
	@RequiresPermissions("module:cloudAcc:remove")
	@Log(title = "云加速管理", action = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{
		int rows = cloudAccService.deleteCloudAccByIds(ids);
		if (rows > 0)
        {
            return success();
        }
        return error();
	}
	
}
